﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ArcSWATMGT
{
    class Program
    {
        #region LaSalle

        static void setMGT_LaSalle()
        {
            string projectMDB = @"C:\zhiqiang\ModelTestWithSWATSQLite\LaSalle\LaSalle2012_DetailedSoil\test\LaSalle2012_DetailedSoil.mdb";
            string swatMDB = @"C:\zhiqiang\ModelTestWithSWATSQLite\LaSalle\LaSalle2012_DetailedSoil\test\swat2012.mdb";

            setNonManureMGT_LaSalle(projectMDB, swatMDB);   //landuse level, all use non-manure and conventional till
            setManureMGT_LaSalle(projectMDB, swatMDB);      //HRU level, change some hru from non-manure to manure
            setTillageType_LaSalle(projectMDB, swatMDB);    //landuse level, change some hru from conventional till to zero till or conservation till

        }

        static void setNonManureMGT_LaSalle(string projectMdb, string swatMdb)
        {
            Console.WriteLine("~~~~~~~~~~~~ All HRUs ~~~~~~~~~~~~");

            using (Project p = new Project(projectMdb,swatMdb))
            {
                string[] landuse_Canola = new string[] 
                        { "OSCA", "PRCA", "FCCA","EPCA","IPCA" };
                string[] landuse_SpringWheat = new string[] 
                        { "OSSW", "PRSW", "FCSW","PFSW","EPSW","ENSW","IPSW"};
                string[] landuse_WinterWheat = new string[] { "FCWW"};
                string[] landuse_Soybean = new string[] { "PRSB"};
                string[] landuse_Carrot = new string[] { "IVCR"};
                string[] landuse_Potato = new string[] { "IVPO","IPPO" };
                string[] landuse_Alfalfa = new string[] { "PFAF" };
                string[] landuse_Corn = new string[] { "ENCN" };
                string[] landuse_WhitePea = new string[] { "EPWB" ,"ENWB"};

                p.MGT.updateMgtSchedule(landuse_Canola, "Canola non-manure conv");
                p.MGT.updateMgtSchedule(landuse_SpringWheat, "SWheat non-manure conv");
                p.MGT.updateMgtSchedule(landuse_WinterWheat, "WWheat non-manure");
                p.MGT.updateMgtSchedule(landuse_Soybean, "Soybean non-manure");
                p.MGT.updateMgtSchedule(landuse_Carrot, "Carrot non-manure");
                p.MGT.updateMgtSchedule(landuse_Potato, "Potato non-manure");
                p.MGT.updateMgtSchedule(landuse_Alfalfa, "Alfalfa non-manure");
                p.MGT.updateMgtSchedule(landuse_Corn, "Corn non-manure");
                p.MGT.updateMgtSchedule(landuse_WhitePea, "WPea non-manure");

                //Feedlots
                p.MGT.updateMgtSchedule("FYDL", "Feedlots");

                //urbn
                p.MGT.updateMgtSchedule("URLD","URLD");
                p.MGT.updateMgtSchedule("URMD", "URMD");
                p.MGT.updateMgtSchedule("UTRN",  "UTRN");

                //others
                p.MGT.updateMgtSchedule("PAST",  "Pasture");
                p.MGT.updateMgtSchedule("HAY", "LaSalleHay");
                p.MGT.updateMgtSchedule("FRSD", "FRSD");
                p.MGT.updateMgtSchedule("WETL",  "WETL");
            }
        }

        static void setManureMGT_LaSalle(string projectMdb, string swatMdb)
        {
            Console.WriteLine("~~~~~~~~~~~~ Manure HRUs ~~~~~~~~~~~~");
            using (Project p = new Project(projectMdb, swatMdb))
            {
                int[] manured_hrus_canola = new int[] { 15, 16, 43, 76, 101, 128, 129, 175, 190, 219, 220, 233, 243, 270, 306, 307, 323, 372, 388, 419, 445, 487, 488, 499, 507, 531, 11, 275, 276, 352, 398 };
                int[] manured_hrus_springwheat = new int[] { 8, 211, 212, 6, 191, 202, 308, 508, 532, 183, 252, 253, 267, 162, 427 };
                int[] manured_hrus_winterwheat = new int[] { 163, 369 };
                int[] manured_hrus_whitepea = new int[] { 254, 255 };
                int[] manured_hrus_corn = new int[] { 182, 251 };

                p.MGT.updateMgtSchedule(manured_hrus_canola, "Canola manure conv");
                p.MGT.updateMgtSchedule(manured_hrus_springwheat, "SWheat manure conv");
                p.MGT.updateMgtSchedule(manured_hrus_winterwheat, "WWheat manure");
                p.MGT.updateMgtSchedule(manured_hrus_whitepea, "WPea manure");
                p.MGT.updateMgtSchedule(manured_hrus_corn, "Corn manure"); 
            }
        }

        static void setTillageType_LaSalle(string projectMdb, string swatMdb)
        {
            Console.WriteLine("~~~~~~~~~~~~ Set Tillage ~~~~~~~~~~~~");
            using (Project p = new Project(projectMdb, swatMdb))
            {
                string[] landuse_with_conservation_till = new string[]{"PRSW","PRCA","FCCA","FCSW","FCWW","PFAF","EPSW","EPCA","EPWB","ENSW"};

                //zero till
                p.MGT.changeFallTillageType(new int[] { 15, 37, 38 }, "OSCA", TillageType.Zero);
                p.MGT.changeFallTillageType(new int[] { 37, 38 }, "OSSW", TillageType.Zero);

                //conservation tillage
                p.MGT.changeFallTillageType(new int[] { 15 }, "OSSW", TillageType.Conservation);
                p.MGT.changeFallTillageType(landuse_with_conservation_till, TillageType.Conservation);
            }
        }
        #endregion

        #region Boyne

        /// <summary>
        /// Inculde all LANDUSE here.
        /// </summary>
        /// <param name="projectMdb"></param>
        /// <param name="swatMdb"></param>
        static void setNonManureMGT_Boyne(string projectMdb, string swatMdb)
        {
            Console.WriteLine("~~~~~~~~~~~~ All HRUs ~~~~~~~~~~~~");

            using (Project p = new Project(projectMdb, swatMdb))
            {
                string[] landuse_Canola = new string[] { "OSCA", "PRCA", "FCCA", "EPCA", "IPCA" };
                string[] landuse_SpringWheat = new string[] { "OSSW", "PRSW", "FCSW","EPSW", "ENSW", "IPSW" };
                string[] landuse_WinterWheat = new string[] { "FCWW" };
                string[] landuse_Soybean = new string[] { "PRSB" };
                string[] landuse_Potato = new string[] { "IPPO" };
                string[] landuse_Alfalfa = new string[] { "PFAF" };
                string[] landuse_Corn = new string[] { "ENCN" };
                string[] landuse_WhitePea = new string[] { "EPWB", "ENWB" };

                p.MGT.updateMgtSchedule(landuse_Canola, "Canola non-manure conv");
                p.MGT.updateMgtSchedule(landuse_SpringWheat, "SWheat non-manure conv");
                p.MGT.updateMgtSchedule(landuse_WinterWheat, "WWheat non-manure");
                p.MGT.updateMgtSchedule(landuse_Soybean, "Soybean non-manure");
                p.MGT.updateMgtSchedule(landuse_Potato, "Potato non-manure");
                p.MGT.updateMgtSchedule(landuse_Alfalfa, "Alfalfa non-manure");
                p.MGT.updateMgtSchedule(landuse_Corn, "Corn non-manure");
                p.MGT.updateMgtSchedule(landuse_WhitePea, "WPea non-manure");

                //urbn
                p.MGT.updateMgtSchedule("URMD", "URMD");
                p.MGT.updateMgtSchedule("UTRN", "UTRN");

                //others
                p.MGT.updateMgtSchedule("PAST", "Pasture");
                p.MGT.updateMgtSchedule("FRSD", "Deciduous");
                p.MGT.updateMgtSchedule("WETN", "WETN");
                p.MGT.updateMgtSchedule("RNGB", "RNGB");
                p.MGT.updateMgtSchedule("WATR", "WATR");
            }
        }

        static void setManureMGT_Boyne(string projectMdb, string swatMdb)
        {
            Console.WriteLine("~~~~~~~~~~~~ Manure HRUs ~~~~~~~~~~~~");
            using (Project p = new Project(projectMdb, swatMdb))
            {
                int[] manured_hrus_canola = new int[] { 10, 50, 74, 88, 111, 117, 132, 134, 150, 152, 162, 164, 165, 173, 175, 181, 187, 209, 216, 217, 224, 234, 235, 245, 254, 267, 268, 279, 301, 339, 342, 350, 354, 357, 403, 409 };
                int[] manured_hrus_springwheat = new int[] { 1, 2, 4, 13, 15, 19, 32, 48, 51, 66, 108, 109, 112, 118, 153, 166, 167, 176, 182, 188, 198, 210, 213, 214, 218, 225, 230, 246, 263, 264, 269, 270, 276, 278, 306, 310, 327, 343, 351, 355, 358, 365, 377, 404, 410 };
                int[] manured_hrus_winterwheat = new int[] { 52, 341, 348, 356 };
                int[] manured_hrus_whitepea = new int[] { 20, 231 };
                int[] manured_hrus_corn = new int[] { 31, 39, 65, 229, 309 };
                int[] manured_hrus_alfalfa = new int[] { 120, 170, 171, 184, 201, 212, 221, 248, 308, 367, 379, 412 };
                int[] manured_hrus_potato = new int[] { 326, 376 };

                p.MGT.updateMgtSchedule(manured_hrus_canola, "Canola manure conv");
                p.MGT.updateMgtSchedule(manured_hrus_springwheat, "SWheat manure conv");
                p.MGT.updateMgtSchedule(manured_hrus_winterwheat, "WWheat manure");
                p.MGT.updateMgtSchedule(manured_hrus_whitepea, "WPea manure");
                p.MGT.updateMgtSchedule(manured_hrus_corn, "Corn manure");
                p.MGT.updateMgtSchedule(manured_hrus_alfalfa, "Alfalfa manure");
                p.MGT.updateMgtSchedule(manured_hrus_potato, "Potato manure");
            }
        }

        static void setTillageType_Boyne(string projectMdb, string swatMdb)
        {
            Console.WriteLine("~~~~~~~~~~~~ Set Tillage ~~~~~~~~~~~~");
            using (Project p = new Project(projectMdb, swatMdb))
            {
                string[] landuse_with_conservation_till = new string[] { 
                 "OSSW","EPSW","EPCA","EPWB","FCCA","FCSW","FCWW","PFAF","PRCA","PRSW"
                };

                //conservation tillage
                //all OSSW would be conservation
                p.MGT.changeFallTillageType(landuse_with_conservation_till, TillageType.Conservation);

                //zero till
                //part of ossw will be changed to zero till
                p.MGT.changeFallTillageType(new int[] { 6,  23, 24,  26, 27, 32,  34,  39, 41 }, "OSCA", TillageType.Zero);
                p.MGT.changeFallTillageType(new int[] { 6,  23, 24,  26, 27, 32,  34,  39, 41 }, "OSSW", TillageType.Zero);
            }
        }

        static void setMGT_Boyne()
        {
            string projectMDB = @"C:\zhiqiang\ModelTestWithSWATSQLite\Boyne\Boyne2012_DetailedSoil\Boyne2012_DetailedSoil.mdb";
            string swatMDB = @"C:\zhiqiang\ModelTestWithSWATSQLite\Boyne\Boyne2012_DetailedSoil\swat2012.mdb";

            setNonManureMGT_Boyne(projectMDB, swatMDB);   //landuse level, all use non-manure and conventional till
            setManureMGT_Boyne(projectMDB, swatMDB);      //HRU level, change some hru from non-manure to manure
            setTillageType_Boyne(projectMDB, swatMDB);    //landuse level, change some hru from conventional till to zero till or conservation till

        }

        #endregion

        static void Main(string[] args)
        {
            setMGT_Boyne();

            Console.WriteLine("Done");
            Console.ReadLine();
        }
    }
}
